<?php
/**
 * Class Infrastructure_Bootstrap
 */
class Infrastructure_Bootstrap
{
    /**
     * @var Infrastructure_Factory
     */
    protected $infrastructureFactory;

    /**
     * @var UserInterface_InputProcessor
     */
    protected $inputProcessor;

    /**
     * @var UserInterface_IInputSecurity
     */
    protected $inputSecurity;

    /**
     * @var Infrastructure_Mapper_Factory
     */
    protected $mapperFactory;

    /**
     * @return Infrastructure_Configuration
     */
    public function getConfiguration()
    {
        $fileName = dirname(__FILE__) . '/../configuration.ini';
        $data = parse_ini_file($fileName, true);
        return new Infrastructure_Configuration($data);
    }

    /**
     * @return Infrastructure_Factory
     */
    public function getInfrastructureFactory()
    {
        return $this->infrastructureFactory;
    }

    /**
     * @return UserInterface_InputProcessor
     */
    public function getInputProcessor()
    {
        return $this->inputProcessor;
    }

    /**
     * @return UserInterface_IInputSecurity
     */
    public function getInputSecurity()
    {
        return $this->inputSecurity;
    }

    /**
     * @return Infrastructure_Mapper_Factory
     */
    public function getMapperFactory()
    {
        return $this->mapperFactory;
    }

    /**
     *
     */
    protected function establishSession()
    {
        session_start();
        date_default_timezone_set('US/Central');
    }

    /**
     *
     */
    public function __construct()
    {
        $this->establishSession();

        $this->infrastructureFactory = new Infrastructure_Factory(
            $this->getConfiguration()
        );

        $this->mapperFactory = new Infrastructure_Mapper_Factory(
            $this->infrastructureFactory->createPDO()
        );

        $this->inputSecurity = new UserInterface_InputSecurity();
        $this->inputProcessor = new UserInterface_InputProcessor($this->inputSecurity);
    }
}
